public class TreeNode {
	int val;
	TreeNode left;
	TreeNode right;
	TreeNode() {}
	TreeNode(int val) { this.val = val; }
	TreeNode(int val, TreeNode left, TreeNode right) {
		this.val = val;
		this.left = left;
		this.right = right;
	}
}

class Solution01 {
	private TreeNode newRoot;
	private TreeNode preNode;

	public TreeNode increasingBST(TreeNode root) {
		inorder(root);
		// System.out.println(newRoot.val);
		return newRoot;
	}

	private void inorder(TreeNode curNode){
		if(curNode != null){
			inorder(curNode.left);
			if(preNode != null){
				// 修改前一个遍历节点的右指针
				preNode.right = curNode;
				// preNode.left = null;
			} else {
				newRoot = curNode;
				System.out.println(newRoot.val);
			}
			// 修改当前遍历节点的左指针
			curNode.left = null;
			preNode = curNode;
			inorder(curNode.right);
		}
	}
}
